package com.atguigu.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @author:zhuguanming
 * @date:2021/4/18
 */
public class ListDoubleValueVerificationValidator implements ConstraintValidator<ListValueVerification, Double> {

    Set<Double> validateDatas = new HashSet<>();

    @Override
    public void initialize(ListValueVerification constraintAnnotation) {
        for (double doubleValue : constraintAnnotation.doubleValues()) {
            validateDatas.add(doubleValue);
        }
    }

    @Override
    public boolean isValid(Double dou, ConstraintValidatorContext constraintValidatorContext) {
        return validateDatas.contains(dou);
    }
}
